#ifndef QIPMSG_H
#define QIPMSG_H

#include "ipmsgcommon.h"
#include "dialogsetting.h"
#include "ipmsgfileserver.h"
#include "ipmsgudpsession.h"
#include "ipmsgfilerecv.h"

namespace Ui {
class QIPMSG;
}

class QIPMSG : public QMainWindow
{
    Q_OBJECT

public:
    explicit QIPMSG(QWidget *parent = nullptr);
    ~QIPMSG();

    QTranslator *qIpMsgLang = nullptr;
    IpMsgUser mSelf;

    // 指定的编码转unicode编码
    QString     toUnicode(QByteArray data);
    // unicode编码转指定的编码
    QByteArray  fromUnicode(QString data);

public slots:
    void userListRefreshTrigger();
    void startChat(QListWidgetItem *item);
    void qIpMsgUdpSessionHandle(QHostAddress src, QByteArray data);
    void qIpMsgFileServerHandle(quint32 ip, quint16 port, QByteArray data);
    void qIpMsgUserListUpdate();
    void qIpMsgConfigration();
    void qIpMsgChatSent(QString data,QHostAddress dest);
    void qIpMsgSettingsAccepted();
    void qIpMsgSettingsRejected();
    void qIpMsgStatus(QString data);

private slots:
   void qIpMsgLangtoEn();
   void qIpMsgLangtoZh();
   void qIpMsgFileTransFinished(quint32 fileId);
   void qIpMsgFileTransProgress(quint32 fileId,int progress);
   void qIpMsgFileTransError(quint32 fileId,int progress);
   void qIpMsgAcceptFile(fileEntryT *file);
   void qIpMsgRejectFile(fileEntryT *file);
   void qIpMsgRecvFileFinish(quint32 fileId);
   void qIpMsgRecvFileError(quint32 fileId);

signals:
   void userListUpdate();
   void changeLang(int lang);


protected:
    void timerEvent(QTimerEvent *event);
    void closeEvent(QCloseEvent *event);

private:
    Ui::QIPMSG          *ui;
    DialogSetting       *mSetPanel = nullptr;
    IpMsgFileServer     *fileServer;
    QList<IpMsgUser*>   mUsers;     /**< 用户类对象 */
    IpMsgUdpSession     session;
    QString mCodec="GBK";           /**< 其它的飞哥传书,使用的是gbk编码器,所以统一使用 gbk */
    unsigned int mStartIp=0;
    unsigned int mEndIp=0;
};

#endif // QIPMSG_H
